package com.sskj.gocoin.v.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.bulong.rudeness.RudenessScreenHelper;
import com.shizhefei.mvc.MVCCoolHelper;
import com.shizhefei.view.coolrefreshview.CoolRefreshView;
import com.sskj.gocoin.MyAppLication;
import com.sskj.gocoin.R;
import com.sskj.gocoin.adapter.slimadapter.IViewInjector;
import com.sskj.gocoin.adapter.slimadapter.SlimAdapter;
import com.sskj.gocoin.adapter.slimadapter.SlimInjector;
import com.sskj.gocoin.common.App;
import com.sskj.gocoin.common.Constants;
import com.sskj.gocoin.common.decoration.DividerLineItemDecoration;
import com.sskj.gocoin.m.bean.FabiListBean;
import com.sskj.gocoin.mvchelper.ModelRx2DataSource;
import com.sskj.gocoin.p.fragment.FabiRecordPresenter;
import com.sskj.gocoin.utils.SPUtils;
import com.sskj.gocoin.utils.ToastUtil;
import com.sskj.gocoin.v.activity.LoginActivity;
import com.sskj.gocoin.v.activity.MainActivity;
import com.sskj.gocoin.v.activity.SecurityCenterActivity;
import com.sskj.gocoin.v.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import io.reactivex.Flowable;

public class FabiRecordFragment extends BaseFragment<MainActivity, FabiRecordPresenter> {
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.coolRefreshView)
    CoolRefreshView coolRefreshView;
    private SlimAdapter slimAdapter;
    private MVCCoolHelper<List<String>> mvcCoolHelper;

    @Override
    public int getLayoutId() {
        return R.layout.fragment_fabi_record;
    }

    @Override
    public FabiRecordPresenter getPresenter() {
        return new FabiRecordPresenter();
    }

    public static FabiRecordFragment newInstance() {
        Bundle args = new Bundle();
        FabiRecordFragment fragment = new FabiRecordFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void initView() {
        super.initView();
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        recyclerView.addItemDecoration(new DividerLineItemDecoration(getActivity())
                .setFirstDraw(false)
                .setPaintWidth((int) RudenessScreenHelper.pt2px(getActivity(), 20))
                .setDividerColor(ContextCompat.getColor(getContext(), R.color.transparent)));
        slimAdapter = SlimAdapter.create().register(R.layout.recy_item_fabi_record, new SlimInjector<String>() {
            @Override
            public void onInject(String data, IViewInjector injector) {

            }
        });
        slimAdapter.attachTo(recyclerView).updateData(new ArrayList());
        Flowable.rangeLong(0, 8)
                .map(i -> i + "")
                .toList()
                .subscribe(strings -> slimAdapter.updateData(strings));
//        ModelRx2DataSource<FabiListBean> dataSource =
//                new ModelRx2DataSource<>((ModelRx2DataSource.OnLoadSource<FabiListBean>)
//                        page -> mPresenter.getFabiList(page, Constants.PAGE_SIZE, isBuy), Constants.PAGE_SIZE);
        mvcCoolHelper = new MVCCoolHelper<>(coolRefreshView);
//        mvcCoolHelper.setDataSource(dataSource);
        mvcCoolHelper.setAdapter(slimAdapter);
        mvcCoolHelper.refresh();
    }
}
